﻿using HandyControl.Controls;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace DA.HMI.ViewModels
{
    class LoginViewModel:BindableBase,IDialogAware
    {
        public LoginViewModel()
        {
            
        }
        private string username;

		public string Username
        {
			get { return username; }
			set { SetProperty(ref username, value); }
		}

		private string password;

		public string Password
		{
			get { return password; }
			set { SetProperty(ref password, value); }
		}
		private string errorMessage;

        

        public string ErrorMessage
        {
			get { return errorMessage; }
			set { SetProperty(ref errorMessage, value); }
		}

		public ICommand LoginCmd
		{
			get => new DelegateCommand(() =>
			{
				if(string.IsNullOrEmpty(username))
				{
					ErrorMessage = "用户名不能为空！";return;
				}
				if(string.IsNullOrEmpty(password))
				{
					ErrorMessage = "密码不能为空！";return;
                }
                if (username == "admin" && password == "123456")
				{
			        RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
                }
                else
				{
                    ErrorMessage = "用户名或密码不正确！";
                }
            });
		}

        public string Title => "登录";
        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
			return true;
        }

        public void OnDialogClosed()
        {
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
        }
    }
}
